<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>await并行执行的技巧</title>
</head>
<body>
    <script>
        function p1(){
            return new Promise(resolve => {
                setTimeout(() => {
                    resolve("hd");
                },2000)
            })
        }

        function p2(){
            return new Promise(resolve => {
                setTimeout(() => {
                    resolve("hdms");
                })
            },2000)
        }

        // 方法一：Promise.all
        // async function hd(){
        //     let res = await Promise.all([p1(),p2()]);
        //     console.log(res);
        // }
        // hd();

        // 方法二：
        async function hd(){
            let h1 = p1();
            let h2 = p2();
            let hlVaule = await h1;
            let h2Vaule = await h2;
            setTimeout(() => {
                console.log(hlVaule,h2Vaule);
            },2000)
        }
        hd();
    </script>
</body>
</html>